package org.canaan.http;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.http.cookie.Cookie;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * org.apache.http.HttpResponse 的代理对象
 * @author Canaan
 * @date 2017/7/17
 */
public class HttpResponse {
    private List<Cookie> cookies; //设置的cookies值
    private Integer httpStatus;         //http状态
    private String data;                //http返回值
    private Long spendTime;          //通信发费时间,毫秒数
    private org.apache.http.HttpResponse target; //真正的对象

    public HttpResponse(org.apache.http.HttpResponse response) {
        super();
        this.target = response;
    }

    public List<Cookie> getCookies() {
        return cookies;
    }

    public Integer getHttpStatus() {
        return httpStatus;
    }

    public void setCookies(List<Cookie> cookies) {
        this.cookies = cookies;
    }

    public void setHttpStatus(Integer httpStatus) {
        this.httpStatus = httpStatus;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public Long getSpendTime() {
        return spendTime;
    }

    public void setSpendTime(Long spendTime) {
        this.spendTime = spendTime;
    }
    public org.apache.http.HttpResponse getTarget() {
        return target;
    }

    @Override
    public String toString() {
        Map<String,Object> temp = new HashMap<>();
        temp.put("httpStatus", this.httpStatus);
        temp.put("spendTime", this.spendTime);
        temp.put("cookies", cookies);
        temp.put("data",this.data);
        return JSON.toJSONString(temp, SerializerFeature.PrettyFormat);
    }
}
